<?php
/*
 * Creative Bulletin Board Generation 3
 * Version 1.0 Beta 1
 +------------------------------------
 * Forum Application, Index Module (Frontend)
 * Started: 30 August, 2009 8:17 AM
 * Script version: 1.0
 +------------------------------------
 */

class module implements module_interface{
	public function returninitvars(){
		global $lang;
		$this->info["page_title"] = $lang->getByKey("forum.index");
		$this->info["page_description"] = "";
		$this->info["module_version"] = "1.0";
		return $this->info;
	}

	public function construct(){ # call our initialize functions
		global $perm;
		if($perm->getValue("can_view_boards") == "0"){
			$this->run = false;
		}
		else $this->run = true;
	}
	
	public function run(){
		global $_CF, $perm;
		$qc = $_CF->models->categories->select_all();
		$qb = $_CF->models->boards->select_all();
		while($array = $_CF->db->fetch_array($qb)){
			// What we are doing is to store all data
			// inside a nifty array which will be for'd later
			// Format: $this->boards[RELCAT][ORDER]
			if($perm->getValue($array['permkey']) == "1"){
				$this->boards[$array['relcat']][$array['order']] = $array;
			}
		}
		while($array = $_CF->db->fetch_array($qc)){
			$content = "";
			for($i=0;$i !== (count($this->boards[$array['id']]));$i++){
				if($this->boards[$array['id']][$i]["type"] == "regular"){ # Regular forum?
					$content .= $_CF->view->showTemplate("forum_reg", $this->boards[$array['id']][$i]);
				}
				elseif(stristr($this->boards[$array['id']][$i]["type"], "redirect") != ""){
					$a = explode("=", $this->boards[$array['id']][$i]["type"], 2);
					$uri = $a[1];
					$this->boards[$array['id']][$i]["url"] = $uri;
					$content .= $_CF->view->showTemplate("forum_red", $this->boards[$array['id']][$i]);
				}
				else{ /* wtf */ }
			}
			$_CF->view->writeIn(
				$_CF->view->tableunpadded(
					$_CF->view->showTemplate("cattitle", $array),
					$content,
					"tag_blue"
				)
			);
		}
				
	}

	public function destruct(){}
}
